package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {
    @Autowired
    private CategoryBrandService categoryBrandService;

    @Operation(summary = "查询分类品牌列表")
    @GetMapping("/list")
    public TableDataInfo list(){
        startPage();
        List<CategoryBrand> list= categoryBrandService.selectCategoryBrandList();
        return getDataTable(list);
    }
    @Operation(summary = "新增分类品牌管理")
    @PostMapping()
    public AjaxResult saveCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.saveCategoryBrand(categoryBrand);
        return AjaxResult.success();
    }


    @Operation(summary = "删除分类品牌管理")
    @DeleteMapping("/{ids}")
    public AjaxResult removeCategoryBrand(@PathVariable List<Long> ids){
        categoryBrandService.removeByIds(ids);
        return AjaxResult.success();
    }

    @Operation(summary = "根据分类id获取品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult selectBrandListByCategoryId(@PathVariable Long categoryId) {
        List<Brand> list= categoryBrandService.brandList(categoryId);
        return success(list);
    }

}
